#include <stdlib.h>
#include <new>
#include <cstring>
#ifndef NEWDEL
#define NEWDEL 1
extern int allocations;

inline void *operator new( size_t size ) throw (std::bad_alloc) 
{
  size += sizeof(size_t);
  char *memory = (char*)malloc(size);

  if(memory != 0)
	{
         ++allocations;
          std::memset(memory,1,size);
	   *(reinterpret_cast<size_t*>(memory)) = size;

	   return (memory + sizeof(size_t));	
	}

   throw std::bad_alloc();
}

inline void operator delete( void * p ) throw() 
{
  --allocations;
  char * memory = reinterpret_cast<char*>(p);
  memory -= sizeof(size_t); //Point to allocated block

  //Get allocated size, and overwrite block
  size_t mem_size = *reinterpret_cast<size_t*>(memory);
  std::memset(memory,1,mem_size);

  //free
  free(memory);
}
#endif // NEWDEL
